//两个参数，一个是cookie的名子，一个是值
function setCookie1(name, value) {
    setCookie2(name, value, 1);//此 cookie 将被保存 1 天
}

function setCookie2(name, value, day) {
    var Days = day;
    var exp = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=/";
}

//取cookies函数
function getCookie(name) {
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return (arr[2]);
    return null;

}

//删除cookie
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}


// function checkCookie() {
//     username = getCookie('username');
//     if(null!=username&&""!=username){
//         alert('Welcome agiin '+username+'!');
//     }else{
//         username = prompt('Please enter your name:',"");
//         if(username!=null&&username!=""){
//             setCookie('username',username,365);
//         }
//     }
// }
//
// function getCookie(c_name) {
//     if(document.cookie.length>0){
//         c_start = document.cookie.indexOf(c_name + "=");
//         if(c_start!=-1){
//             c_start = c_start + c_name.length+1;
//             c_end = document.cookie.indexOf(";",c_start);
//             if(c_end==-1){
//                 c_end=document.cookie.length;
//                 return unescape(document.cookie.substring(c_start,c_end));
//             }
//         }
//     }
// }
//
// function setCookie(c_name, value, expiredays) {
//     var exdate = new Date();
//     exdate.setDate(exdate.getDate()+expiredays);
//     document.cookie=c_name+"="+escape(value)+
//         ((expiredays==null) ? "":";expires="+exdate.toGMTString());
// }